import {
    request
} from "./request";

//登录
export const reqLogin = (params) => request({
    url: 'login',
    method: 'post',
    data: params
})


// 左侧权限列表
export const reqtMenus = () => request({
    url: 'menus',
    method: 'get'
})

//用户列表
export const reqUsers = (params) => request({
    url: 'users',
    method: 'get',
    params
})

//修改状态
export const reqSwitch = (type) => request({
    url: `users/${type.id}/state/${type.mg_state}`,
    method: 'put'
})

//添加用户
export const reqAdd = (data) => request({
    url: 'users',
    method: 'post',
    data
})

//修改用户
export const reqAlter = (id) => request({
    url: `users/${id}`,
    method: 'get'
})

// 完成修改提交
export const reqSucc = (alteruser) => request({
    url: `users/${alteruser.id}`,
    method: 'put',
    data: {
        email: alteruser.email,
        mobile: alteruser.mobile
    }
})

//删除角色
export const reqDel = (id) => request({
    url: `users/${id}`,
    method: 'delete'
})

//所有权限列表
export const reqPower = () => request({
    url: 'rights/list',
    method: 'get'
})

//角色权限
export const reqRole = () => request({
    url: 'roles',
    method: 'get'
})

//删除权限
export const reqDelRole = (roleId, rightId) => request({
    url: `roles/${roleId}/rights/${rightId}`,
    method: 'delete'
})

//分配权限
export const reqDis = () => request({
    url: 'rights/tree',
    method: 'get'
})

//完成分权
export const reqCheRole = (id, rids) => request({
    url: `roles/${id}/rights`,
    method: 'post',
    params: rids
})

//主页修改权限
export const reqDisRole = (id, rid) => request({
    url: `users/${id}/role`,
    data: {
        rid
    },
    method: 'put'
})

//商品列表
export const reqGoodList = (queryInfo) => request({
    url: 'categories',
    method: 'get',
    params: {
        type: queryInfo.type,
        pagenum: queryInfo.pagenum,
        pagesize: queryInfo.pagesize
    }
})

//分级分类列表
export const reqParentCateList = () => request({
    url: 'categories',
    params: {
        type: 2
    },
})

// 完成添加分类
export const reqCate = (data) => request({
    url: 'categories',
    method: 'post',
    data
})

//分级分类列表
export const reqCateList = () => request({
    url: 'categories',
    method: 'get'
})

// 获取动静态参数
export const reqDyOrSt = (id, activeName) => request({
    url: `categories/${id}/attributes`,
    params: {
        sel: activeName
    },
    method: 'get'
})

export const reqCatealter = (id) => request({
    url: `categories/${id}`,
    method: 'get'
})

export const reqCatedel = (id) => request({
    url: `categories/${id}`,
    method: 'delete'
})

// 编辑提交分类
export const reqCatesu = (cateAlter) => request({
    url: `categories/${cateAlter.cat_id}`,
    method: 'put',
    data: {
        cat_name: cateAlter.cat_name
    }
})

// 完成动静态添加
export const reqsuDyOrSt = (id, name1, name2) => request({
    url: `categories/${id}/attributes`,
    method: 'post',
    data: {
        attr_name: name1,
        attr_sel: name2
    }
})

// 修改动静态属性
export const reqalterDyOrSt = (id, attrId, name1, name2) => request({
    url: `categories/${id}/attributes/${attrId}`,
    method: 'put',
    data: {
        attr_sel: name1,
        attr_name: name2
    }
})

//删除
export const reqdelAtt = (id, arrrid) => request({
    url: `categories/${id}/attributes/${arrrid}`,
    method: 'delete'
})

// 添加tag
export const reqAddTag = (id, attr_id, data) => request({
    url: `categories/${id}/attributes/${attr_id}`,
    method: 'put',
    data
})

// 商品列表数据
export const reqGoodsList = (params) => request({
    url: 'goods',
    params,
    method: 'get'
})

//删除商品
export const reqDelGood = (id) => request({
    url: `goods/${id}`,
    method: 'delete'
})

// 添加部分获得属性id
// export const reqById = (id) => request({
//     url: `categories/${id}/attributes`,
//     method: 'get'
// })

// 上传图片
export const requrg = (file) => request({
    url: 'upload',
    data: file,
    method: 'post'

})

// 根据id查询商品
export const reqById = (id) => request({
    url: `goods/${id}`,
    method: 'get'
})

// 完成添加商品
export const reqaddshop = (form) => request({
    url: 'goods',
    method: 'post',
    data: form
})

// 订单列表
export const reqOrder = (params) => request({
    url: 'orders',
    method: 'get',
    params
})
